<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">    
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<link rel="stylesheet" type="text/css" href="css/maintable.css" ></link>
<script type="text/javascript" src="js/jquery-1.8.0.js"></script>
</head>
	
<body>


	<div class="div_title">
		<div class="div_titlename">
			<img src="images/san_jiao.gif"><span>角色权限分配 | 当前角色 : ${roleinfo.roleName}</span>
		</div>
	</div>
	<form action="RoleServlet.do" method="post">
		<input type="hidden" name="flag" value="edit" />
		<input type="hidden" name=roleId value="${roleinfo.id }" />
		<table class="main_table">
			<tr>
				<th>一级菜单</th>
				<th>二级菜单</th>
			</tr>
			
			<c:forEach var="menu" items="${menuList}">
				<tr>
					<td>
						<input type="checkbox" id="${menu.id}" name="menuId"  value="${menu.id}" />${menu.menuName}
					</td>	
						
					<td>
						<c:forEach var="m_sub" items="${menu.subMenuList}">
							<input type="checkbox" id="${m_sub.id}" name="menuId" class="${menu.id}" value="${m_sub.id}" />${m_sub.menuName } <br/>
					  	
					  	<script>
							$(function(){
								$("#${menu.id}").click(function(){
									
									if(this.checked){
										$("#${m_sub.id}").attr("checked", true);
									}else {
										$("#${m_sub.id}").attr("checked", false);
									}
								});
							});
							
							$("#${m_sub.id}").click(function(){
								if(this.checked){
									$("#${menu.id}").attr("checked", true);
								}else if($("input[class='${menu.id}']:checked").length==0){
									$("#${menu.id}").attr("checked", false);
								}
							});
							
							
						</script>
					  	
					  	
					  	</c:forEach>
					</td>
				</tr>	
				
				
				
			</c:forEach>	
			
			<tr>
				<td>
					<input id="form_btn" class="form_btn" type="submit" value="保存修改" /> 
				</td>
				<td>
				</td>
			</tr>	
		</table>
	</form>
	
	<script>
		var menuIdStr="${menuIdStr}";
		var menuIdArray = menuIdStr.split(",");
		Array.prototype.contains=function(e){
 			for(var i=0;i<this.length;i++){
 				if(this[i]==e){
 					return true;
 				}
 			}
 			return false;
 		}
 		
 		$("input[type=checkbox]").each(function(){
 			if(menuIdArray.contains(this.value)){
 				this.checked=true;
 			}	
 		});
		
	</script>
	
 	<script>
		var msg_edit='${msg_edit}';
	 	 if(msg_edit!=''){
	 	 	alert(msg_edit);
	 	 }		  	 
	</script>
	
	
</body>
</html>
